package cn.com.blackboard.DataModule4B2.MemoryCache;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.com.blackboard.DataModule4B2.model.CourseInfo;

public class CourseInfoMemCache {
	private static HashMap<String, CourseInfo> cacheMap = new HashMap<String, CourseInfo>();
	
	public static boolean isEmpty(){
		return cacheMap.isEmpty();
	}
	
	public static CourseInfo getRecordByKey(String key){
		return cacheMap.get(key);
	}
	
	public static List<CourseInfo> getListByKeyList(List<String> keyList){
		List<CourseInfo> uiList = new ArrayList<CourseInfo>();
		for(String key:keyList){
			uiList.add(getRecordByKey(key));
		}
		return uiList;
	}

	public static HashMap<String, CourseInfo> getCacheMap() {
		return cacheMap;
	}

	public static void setCacheMap(HashMap<String, CourseInfo> cacheMap) {
		CourseInfoMemCache.cacheMap = cacheMap;
	}
	
	public static void clear(){
		CourseInfoMemCache.cacheMap.clear();
	}
	
	public static void cacheCourseInfo(List<CourseInfo> courseInfoList){
		for(CourseInfo ci:courseInfoList){
			cacheMap.put(ci.getCourseId(), ci);
		}
	}
}
